package com.wkbb.basic.service.impl;

import com.wkbb.basic.mapper.OrganizationWebankMapper;
import com.wkbb.basic.model.OrganizationWebank;
import com.wkbb.basic.service.OrganizationWebankService;
import com.wkbb.basic.service.WebankUtilService;
import com.wkbb.common.base.BaseServiceImpl;
import com.wkbb.common.config.ServiceConfig;
import com.wkbb.common.redis.RedisTemplateUtil;
import com.wkbb.common.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lilin
 */
@Service
@Slf4j
public class OrganizationWebankServiceImpl extends BaseServiceImpl<OrganizationWebank> implements OrganizationWebankService {


    @Autowired
    private RedisTemplateUtil redisTemplateUtil;

    @Autowired
    private OrganizationWebankMapper organizationWebankMapper;

    @Autowired
    private WebankUtilService webankUtilService;

    @Autowired
    private ServiceConfig serviceConfig;

    @Autowired
    public void setMapper(OrganizationWebankMapper mapper) {
        super.setMapper(mapper);
    }


    @Override
    @Transactional
    public void insert(OrganizationWebank organizationWebank) throws Exception {

        super.insert(organizationWebank);
    }

    @Override
    @Transactional
    public void update(OrganizationWebank entity) throws Exception {
        super.update(entity);
    }

    @Override
    public OrganizationWebank getOrganizationWebank(){
        return organizationWebankMapper.getOrganizationWebank();
    }

    @Override
    public OrganizationWebank getValidOrganizationWebank(){
        return organizationWebankMapper.getValidOrganizationWebank();
    }


    @Override
    public OrganizationWebank getOrganizationWebanksByOrgId(Long orgId,String weBankAppid) {
        Map<String,Object> paramMap = new HashMap<>();

        if(StringUtil.isNotEmptyIgnoreBlank(weBankAppid)){
            paramMap.put("webankAppid",weBankAppid);
        }else if(null!=orgId){
            paramMap.put("orgId",orgId);
        }


        List<OrganizationWebank> organizationWebankList = organizationWebankMapper.getListByMapParams(paramMap);

        if(CollectionUtils.isNotEmpty(organizationWebankList)){

            return organizationWebankList.get(0);
        }
        return null;
    }

    @Override
    public List<OrganizationWebank> getOrganizationWebanksInProgress() {
        return organizationWebankMapper.getOrganizationWebanksInProgress();
    }

}
